﻿using System;
using System.Web.UI;
using VitCode.Castle.DataAccess;
using VitCode.Castle.Entities;
using VitCode.Castle.Helper;
using VitCode.Web.UI.WebControls;

namespace CRS.Web.BackStageManagement
{
    public partial class PassSelf : VcPage
    {
     
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if(String.IsNullOrEmpty(GenericContext.CurrUserCode))
            {
                Response.Redirect("../Default.aspx");
            }
            
            if(!IsPostBack)
            {
                ZLTextBox_AdminName.Text = GenericContext.CurrUserCode;
              
                ZLTextBox_AdminName.Enabled = false;

                ZLTextBox_AdminRealName.Text = GenericContext.CurrUserName;
                ZLTextBox_AdminRealName.Enabled = false;

            }
        }
 

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            CastleAccess acc = new CastleAccess();
          
            try
            {
                var objUser = acc.GetObjectList(new User().GetType().Name, "Code", ZLTextBox_AdminName.Text);
                if (objUser != null && objUser.Count > 0)
                {
                    User user = (User)objUser[0];
                    string strPassword = publ.VitEnctyptString(ZLTextBox_AdminPass.Text.Trim());
                    user.Password = strPassword;

                    acc.SaveOrUpdateObj(user);
                    Alert.MessageBox("修改成功!");

                }
            }
            catch (Exception)
            {
                
            }
            

        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Window.Close();
        }
    }
}
